export const roleOptions = [
    {value: 1, label: '用户', type: 'primary'},
    {value: 2, label: '商家', type: 'info'},
    {value: 3, label: '管理员', type: 'warning'},
]
export const statusOptions = [
    {value: 0, label: '禁用', type: 'primary'},
    {value: 1, label: '正常', type: 'info'},
]

export const fields = [
    {
        prop: 'avatar',
        label: '头像',
        type: 'image',
        width: 120,
    },
    {
        prop: 'username',
        label: '账号',
        type: 'text',
        search: true,
        width: 170,
        rule: {
            min: 5,
            max: 20,
            required: true,
            message: `请输入5-20位的账号`,
            trigger: 'blur'
        }
    },
    {
        prop: 'password',
        label: '密码',
        type: 'text',
        width: 170,
        hidden: true,
        rule: {
            min: 5,
            max: 20,
            required: true,
            message: `请输入5-20位的账号`,
            trigger: 'blur'
        }
    },
    {
        prop: 'nickname',
        label: '昵称',
        type: 'text',
        search: true,
        width: 170,
        rule: {
            min: 2,
            max: 10,
            required: true,
            message: `请输入2-10位的昵称`,
            trigger: 'blur'
        }
    },
    {
        prop: 'phone',
        label: '手机号',
        type: 'text',
        search: true,
        width: 170,
        rule: {
            min: 11,
            max: 11,
            required: true,
            message: `请输入11位的手机号`,
            trigger: 'blur'
        }
    },
    {
        prop: 'email',
        label: '邮箱',
        type: 'text',
        search: true,
        width: 170,
        rule: {
            validator: (rule, value, callback) => {
                const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
                if (!value) {
                    callback(new Error('请输入邮箱地址'));
                } else if (!emailPattern.test(value)) {
                    callback(new Error('请输入有效的邮箱地址'));
                } else {
                    callback(); // 验证通过
                }
            },
            trigger: 'blur'
        }
    },
    {
        prop: 'role',
        label: '角色',
        type: 'tag',
        options: roleOptions,
        search: true,
        width: 120,
    },
    {
        prop: 'status',
        label: '状态',
        type: 'switch',
        options: statusOptions,
        search: true,
        width: 170,
        requireRoles: ['admin']
    },
    {
        prop: 'lockTime',
        label: '冻结时间',
        type: 'datetime',
        width: 190,
        formHidden: true,
    },
    {
        prop: 'location',
        label: '定位',
        type: 'text',
        width: 170,
        formHidden: true,
        hidden: true,
    },
    {
        prop: 'creditScore',
        label: '信用分',
        type: 'rating',
        width: 160,
        formHidden: true,
    },
    {
        prop: 'createTime',
        label: '创建时间',
        type: 'datetime',
        formHidden: true,
        width: 190,
    }
]